package com.qf.flash.mvp.presenter;

import android.text.TextUtils;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.constant.FlashCodes;
import com.qf.flash.http.HttpManager;
import com.qf.flash.http.response.GameDetailResponse;
import com.qf.flash.mvp.contract.GameDetailContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

import java.util.ArrayList;

/**
 * 描述: 组队详情
 * 2020/3/24 14:20
 */
public class GameDetailPresenter extends BasePresenter<GameDetailContract.View> implements GameDetailContract.Presenter {
    @Override
    public void getGameDetail(String id) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .GAME_DETAIL(uid, id)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<GameDetailResponse>(mRootView) {
                    @Override
                    public void onSuccess(GameDetailResponse game) {
                        dealMemberData(game);
                        mRootView.setGDetail(game);
                    }
                })
        );
    }

    //处理成员获得的角色信息
    private void dealMemberData(GameDetailResponse response) {
        if (response == null)
            return;
        ArrayList<GameDetailResponse.UsersBean> users = response.getUsers();
        for (GameDetailResponse.UsersBean user : users) {
            if (TextUtils.equals(user.getUid(), response.getMvpUser())) {
                user.addPlayEvaluate(FlashCodes.SCORE_MVP);
            }
            if (TextUtils.equals(user.getUid(), response.getZhUser())) {
                user.addPlayEvaluate(FlashCodes.SCORE_WISDOM);
            }
            if (TextUtils.equals(user.getUid(), response.getYzUser())) {
                user.addPlayEvaluate(FlashCodes.SCORE_BEAUTY);
            }
            if (TextUtils.equals(user.getUid(), response.getYqUser())) {
                user.addPlayEvaluate(FlashCodes.SCORE_COURAGE);
            }
        }

    }

}
